<?php


namespace app\api\controller\mall;


use app\api\controller\ApiBase;
use app\common\business\Goods;
use app\common\lib\Show;

//商品检索 商品列表页
class Lists extends ApiBase
{
    public function index()
    {
        //接收数据 每页显示多少条
        $pageSize = input("param.page_size", 10, "intval");
        //从哪个ID进来的
        $categoryId = input("param.category_id", 0, "intval");
        //搜索
        $keyword =input("param.keyword","","trim");

        //价格排序
        $field = input("param.field", "listorder", "trim");
        $order = input("param.order", 2, "intval");
        $order = $order == 2 ? "desc" : "asc";
        $order = [$field => $order];
        //如果没有ID 就是搜索
        if (!$categoryId) {
            $data['title'] = $keyword;
            $goods = (new Goods())->getSearchLists($data, "5",$order);
            return Show::success($goods);
        }

        $data = [
            "category_path_id" => $categoryId
        ];
        // 商品列表页逻辑
        $goods = (new Goods())->getNormalLists($data, $pageSize, $order);

        return Show::success($goods);

    }
}